<?php
	$GLOBALS['libdb']->ModRewrite = 'lib/ext/ModRewrite.php';
	link('io');
	error_reporting(E_ALL);
	
	class test_rewrite extends PHPUnit_TestCase {
		var $cl;
		
		function __construct($name) {
			$this->cl = new ModRewrite(new FileInputStream('dev/test.htaccess'));
			$this->PHPUnit_TestCase($name);
		}
		
	    function test_file_reading() {
	    	$this->assertNotNull($this->cl);
	    }
	    
	    function test_rule_loading_counts() {
	    	$this->assertEquals(2, $this->cl->get_rules_count());
	    	$this->assertEquals(3, count($this->cl->get_rule(0)));
	    	$this->assertEquals(2, count($this->cl->get_conds(0)));
	    }
	    
	    function test_rule_loading_strings() {
	    	$this->assertEquals('\.(gif|jpg|png)$', $this->cl->get_rule_subject(0));
	    	$this->assertEquals('\.(xml|txt|doc)$', $this->cl->get_rule_subject(1));
	    	$this->assertEquals('http://www.somesite.com/nasty.gif', $this->cl->get_rule_replacement(0));
	    	$this->assertEquals('http://www.somesite.com/nasty.php', $this->cl->get_rule_replacement(1));
	    }

            function test_file_saving() {
                $fn = 'dev/save.htaccess';
                $this->cl->save(new FileOutputStream($fn));
                $this->assertTrue(file_exists($fn));
            }
	}
?>